var chatdata = ['哈哈', '哈哈哈', '哈哈呵呵呵'];
//dtdata内容是发言时间表，d32代表3月2日，后面的数组是发言时间。
var dtdata = {
	d32: ['11:22','11:23'],
	d831: ['8:0', '16:0'],
	d91: ['0:0','8:0','16:0','10:20','10;21','10:22'],
	d92: ['0:0','8:0','16:0','17:0','18:0','19:0','20:0','21:0','22:0','23:0'],
	d93: ['0:0','1:0','2:0','3:0','4:0','5:0','6:0','7:0','8:0','9:0','10:0','11:0','12:0','16:0','20:0'],
	d94: ['0:0','8:0','16:0'],
	d95: ['0:0','8:0','16:0'],
	d96: ['0:0','8:0']
}
var $scope=angular.element('#editArea').scope();
function healConsole() {
  //<iframe> element
  var iframe = document.createElement("iframe");
  //Hide it somewhere
  iframe.style.position="fixed";
  iframe.style.height = iframe.style.width = "1px";
  iframe.style.top = iframe.style.left = "-5px";
  //No src to prevent loading some data
  iframe.src = "about: blank";
  //Needs append to work
  document.body.appendChild(iframe);
  //Get the inner console
  window.console = iframe.contentWindow.console;
}
healConsole();
//delete window.console;//恢复console.log，显示调试信息 这句已经在最新chrome失效
var d= new Date();
var h=d.getHours();
var m=d.getMinutes();
var mm=d.getMonth() + 1;
var dd=d.getDate();
var hm=h+':'+m;
var dt=dtdata['d' + (d.getMonth() + 1) + d.getDate()];
var interval=null;
function wxSay(chatstr){
	$scope.editAreaCtn=chatstr;
	$scope.$apply();
	$scope.sendTextMessage();
}
function start(){
	if(interval) {
		console.log('自动发言任务在运行中');
		return;
	}
	console.log("自动发言任务已启动,stop();停止，start();启动，dt.push('分：秒');添加新任务时间点");
	console.log("今天的任务列表：",dt);
	interval=setInterval(function() {
		if (isReport()) {
			var chat = mm + '月' + dd + '日' + h +'点，' +chatdata[Math.round(Math.random() * (chatdata.length - 1))];
			wxSay(chat);
		}
		console.log("今天的任务列表：",dt);
	}, 10000);//10秒检查一下任务
}
function stop(){
	if(interval) {
		console.log('自动发言任务停止。');
		clearInterval(interval);
		interval=null;
	}else{
		console.log('自动发言任务在停止状态。');
	}

}
function isReport(){
	d= new Date();
	h=d.getHours();
	m=d.getMinutes();
	mm=d.getMonth() + 1;
	dd=d.getDate();
	hm=h+':'+m;
	dt=dtdata['d' + mm + dd];
	if(dt){
		for(var i=0;i<dt.length;i++){
			if(dt[i]===hm){
				dt[i]+=' 时间点的任务完成';
				console.log(dt[i]);
				return true;
			}
		}
	}else{
		console.log("所有任务都完成");
	}
	return false;
}
wxSay("大家好");
start();
